package 双指针;

/**
 * @description: 有序数组去重
 * @author: ywk
 * @date: 2021-01-08
 */
public class 删除重复 {
    public static void main(String[] args) {
        System.out.println(removeDuplicate(new int[]{1, 2, 2, 4, 4, 5}));
    }

    private static int removeDuplicate(int[] arr) {
        int i = 0;
        for (int j = i + 1; j < arr.length; ) {
            if (arr[i] != arr[j]) {
                arr[++i] = arr[j];
            }
            j++;
        }
        System.out.println(arr);
        return i + 1;
    }
}
